#! /bin/sh

# Add a simple annotation-style subtitle to a given MPEG video

SRT_FILE="makesub.srt"
XML_FILE="makesub.xml"

SPU_XML=`cat << EOF
<subpictures>
    <stream>
        <textsub filename="$SRT_FILE"
                 fontsize="28.0"
                 font="arial.ttf" />
    </stream>
</subpictures>
EOF`

if test $# -ne 2; then
    echo "Usage: makesub \"Text to add\" MPEG_FILE"
    exit 1
fi

SUB_TEXT="$1"
INFILE="$2"

printf "Adding text: \"$SUB_TEXT\" to file $INFILE\n"

SRT_OUTPUT=`cat << EOF
1
00:00:00.00 --> 00:00:02.00
$SUB_TEXT

2
00:00:02.50 --> 00:00:04.00
$SUB_TEXT
EOF`

printf "%s\n" "$SRT_OUTPUT" > "$SRT_FILE"
printf "%s\n" "$SPU_XML" > "$XML_FILE"

printf "Running spumux...\n"
spumux -v 2 "$XML_FILE" < "$INFILE" > "$INFILE.subbed.mpg"

printf "Done!\n"

